package design.pattern.Strategy.context;

import design.pattern.Strategy.enumeration.ResponseStateEnum;
import design.pattern.Strategy.handle.StrategyHandle;

import java.util.HashMap;
import java.util.Map;

/**
 * 从 这里 定义策略工厂
 *
 * @author lihh
 */
public class StrategyFactory {
  private static final Map<ResponseStateEnum, StrategyHandle> map = new HashMap<>();
  
  /**
   * 注册 策略
   *
   * @param state  策略状态
   * @param handle 策略事件
   * @author lihh
   */
  public static void register(ResponseStateEnum state, StrategyHandle handle) {
    map.put(state, handle);
  }
  
  /**
   * 根据 状态 拿到 策略事件
   *
   * @param state 策略状态
   * @return 策略事件
   * @author lihh
   */
  public static StrategyHandle get(ResponseStateEnum state) {
    return map.get(state);
  }
}
